package com.xhblog.controller;

import com.xhblog.entity.dto.PageDto;
import com.xhblog.result.Result;
import com.xhblog.service.ArticleService;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author pengyouhong
 * create 2022/5/17 18:17
 */

@RestController
@Log4j2
@RequestMapping("articles")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    /**
     * 首页文章列表
     *
     * @param pageDto 分页对象，包含页大小和页索引
     * @return 返回统一结果集对象，包含分页后的文章列表集合
     */
    @PostMapping
    public Result listArticle(@RequestBody PageDto pageDto) {

        log.info(pageDto);

        Result result = articleService.listArticle(pageDto);

        return result;
    }


    /**
     * @return 最热文章
     */
    @PostMapping("hot")
    public Result hotArticle() {
        int limit = 5;
        return articleService.hotArticle(limit);
    }

    /**
     * @return 最新文章
     */
    @PostMapping("new")
    public Result newArticle() {
        int limit = 5;
        return articleService.newArticle(limit);
    }

    @PostMapping("listArchives")
    public Result listArchives() {
        return articleService.listArchives();
    }
}
